package com.ctshk.rpc.air.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.air.entity.AirProductSaleStrategy;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;

/**
 * <p>
 * 机票销售加幅策略 Mapper 接口
 * </p>
 *
 * @author lihang
 * @since 2021-03-09
 */
public interface AirProductSaleStrategyMapper extends BaseMapper<AirProductSaleStrategy> {

    /**
     * 获取有效时间的加幅策略
     * @param productId
     * @param now
     * @return
     */
    @Select("SELECT \n" +
            "  ass.* \n" +
            "FROM\n" +
            "  `t_air_product_sale_strategy` ass \n" +
            "  LEFT JOIN `t_air_product_sale_strategy_vaild_date` assv \n" +
            "    ON assv.`strategy_id` = ass.`id` \n" +
            "WHERE ass.`product_id` = #{productId} \n" +
            "  AND #{now} BETWEEN assv.`time_begin` \n" +
            "  AND assv.`time_end` \n" +
            "ORDER BY assv.gmt_create ASC \n" +
            "LIMIT 1 ")
    AirProductSaleStrategy getValidDateStrategy(@Param("productId") Long productId,@Param("now") LocalDate now);
}
